<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>代理商监控</title>
    <link rel="stylesheet" type="text/css" href="/themes/default/easyui.css" id="swicth-style">
    <link rel="stylesheet" type="text/css" href="/css/icon.css">
    <link rel="stylesheet" type="text/css" href="/css/common.css">
    <link rel="stylesheet" type="text/css" href="/themes/icon.css">
    <link rel="stylesheet" type="text/css" href="/themes/color.css">
    <script type="text/javascript" src="/js/jquery.min.js"></script>
    <script type="text/javascript" src="/js/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="/js/jquery.cookie.js"></script>
    <script type="text/javascript" src="/js/easyui-lang-zh_CN.js"></script>
    <script type="text/javascript" src="/js/common.js"></script>
</head>

<body class="easyui-layout" style="padding:5px">
<fieldset>
    <legend>信息查询</legend>
    <form id="ffSearch" method="post">
        <div id="searchBar">
            <table cellspacing="0" cellpadding="0">
                <tr>
                    <th>统一社会信用代码：</th>
                    <td style="width:120px"><input type="hidden" name="type" value="1"/>
                        <input name="companySocialCode" class="easyui-textbox" type="text" style="width:100px">
                    </td>
                    <th>公司名称：</th>
                    <td style="width:120px">
                        <input name="companyName" class="easyui-textbox" type="text" style="width:100px">
                    </td>
                    <th>公司地址：</th>
                    <td style="width:120px">
                        <input name="address" class="easyui-textbox" type="text" style="width:100px">
                    </td>
                    <!--<th>公司类型：</th>
                    <td style="width:120px">
                        <select id="typeSelect" name="type" class="easyui-combobox" data-options="onSelect: function(rec){onSearch()}" style="width:100px">
                            <option value="-1">全部</option>
                            &lt;!&ndash;<option value="0">平台公司</option>&ndash;&gt;
                            <option value="1">代理商</option>
                            <option value="2">合作伙伴</option>
                        </select>
                    </td>-->
                    <td colspan="2">
                        <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-search'" onclick="onSearch()">查询</a>&nbsp;&nbsp;
                        <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-clear'" onclick="onClear()">重置</a>
                    </td>
                </tr>
            </table>
        </div>
    </form>
</fieldset>
<table id="dg"> </table>
<!--电站-->
<div id="station" class="easyui-window" title="电站列表" data-options="closed:true,iconCls:'icon-save',footer:'#ft1'"  style="width:70%;paddin:100px;">
    <div id="station_dl"></div>
    <div id="station_ft1" style="padding:5px;text-align: right;">
        <a class="easyui-linkbutton" data-options="iconCls:'icon-cancel'" href="javascript:void(0)" onclick="closeWindow()" style="width:80px">关闭</a>
    </div>
</div>
<!--合作伙伴-->
<div id="partner" class="easyui-window" title="合作伙伴列表" data-options="closed:true,iconCls:'icon-save',footer:'#ft1'"  style="width:70%;paddin:100px;">
    <div id="partner_dl"></div>
    <div id="partner_ft1" style="padding:5px;text-align: right;">
        <a class="easyui-linkbutton" data-options="iconCls:'icon-cancel'" href="javascript:void(0)" onclick="closeWindow()" style="width:80px">关闭</a>
    </div>
</div>
<!--金融详情-->
<div id="finance" class="easyui-window" title="账户余额" data-options="closed:true,iconCls:'icon-save',footer:'#finance_ft1'"  style="width:30%;paddin:100px;height:200px;">
    <div id="finance_dl" align="center">
        <table id="finance_table"  style="width:100%;height:124px;" class="table-blue">
            <tr>
                <th>公司账户余额：</th><td align="center"><span id="balance"> 10000</span></td><th>收益账户余额：</th><td align="center"><span id="profit"> 10000</span></td>
            </tr>
            <tr>
                <th>充值账户余额：</th><td align="center"><span id="recharge"> 10000</span></td><th>网间账户余额：</th><td align="center"><span id="internet"> 10000</span></td>
            </tr>
        </table>
    </div>
    <div id="finance_ft1" style="padding:5px;text-align: right;">
        <a class="easyui-linkbutton" data-options="iconCls:'icon-cancel'" href="javascript:void(0)" onclick="closeWindow()" style="width:80px">关闭</a>
    </div>
</div>

<div id="showImageId" class="easyui-window" title="营业执照" data-options="closed:true" style="width:600px;height:400px;padding:10px;">
    <div style="float: left;">
        <img alt="" src="/images/default.jpg" width="100%" height="100%" id="showCompanyImageId">
    </div>
</div>

<script type="text/javascript">
    $(function(){
        var dg = $('#dg').datagrid();
        var queryParams = $('#ffSearch').serializeObject();
        $('#ffSearch').form('clear');
        dg.datagrid({
            url:'/v1/api0/company_agent_Spy/list',
            queryParams: queryParams,
            columns:[[
                {field:'id',checkbox:true},
                {field:'companyName',title:'公司名称',width:100},
                {field:'companySocialCode',title:'统一社会信用代码',width:100,
                 formatter:function (value, row, index) {
                 return '<a href="#" onclick="showRowImg(' + index + ')">'+row.companySocialCode+'</a>';
                }},
                {field:'leaderName',title:'负责人名称',width:50},
                {field:'companyMobile',title:'手机号',width:60},
                {field:'address',title:'公司地址',width:100},
                {field:'agreementName',title:'合作协议',width:100,formatter: function(value,row,index){
                if(row.agreementName!='null'&&row.agreementName!=null&&row.agreementName!='undefined'&&row.agreementPath!='null'&&row.agreementPath!=null&&row.agreementPath!='undefined'){
                    return  '<a href='+serverPath+'/GetFile?fn='+row.agreementName+'&bt=informationFile&pt='+row.agreementPath+'>'+row.agreementName+'</a>';
                    }
                }},
                {field:'totalStation',title:'电站总数',width:50},
                {field:'totalPartner',title:'合作伙伴总数',width:50},
                {field:'action',title:'操作',formatter: function(value,row,index){
                        return '<a href="javascript:void(0)" class="easyui-linkbutton" onclick="listStation(\''+row.companyID+'\')">查看电站详情</a> | ' +
                            '<a href="javascript:void(0)" class="easyui-linkbutton" onclick="listPartner(\''+row.companyID+'\')">查看合作伙伴详情</a>  | '+
                        '<a href="javascript:void(0)" class="easyui-linkbutton" onclick="showFinanceWindow(\''+row.companyID+'\');">查看金融详情</a>';
                }}
            ]],
            MaxWidth:'',
            title:'代理商监控',
            pagination: true,
            iconCls: 'icon-application_view_detail',
            singleSelect: false,
            toolbar: [ {
                id: 'btnReload',
                text: '刷新',
                iconCls: 'icon-reload',
                handler: function () {
                    $("#dg").datagrid("reload");
                }
            }]
        });

        var heightMargin = $("#searchBar").height() + 45;
        $('#dg').resizeDataGrid(heightMargin, 0, 0, 0);
        $(window).resize(function() {
            $('#dg').resizeDataGrid(heightMargin, 0, 0, 0);
        });
    });

    function onSearch(){
        var queryParams = $('#ffSearch').serializeObject();
        $('#dg').datagrid({
            url:'/v1/api0/company_agent_Spy/list',
            queryParams: queryParams
        });
    }

    function onClear() {
        $('#ffSearch').form('clear');
        $('#statusSelect').combobox('setValue', '0');
        onSearch();
    }
    //列出电站
    function listStation(companyID){
    showStationWindow(companyID);
    }
    function showStationWindow(id) {
       var  queryParams = id;
       var dg = $('#station_dl').datagrid();
       dg.datagrid({
            url:'/v1/api0/equipment/stationList',
            queryParams: {managerId:queryParams},
            columns:[[
                {field:'id',title:'电站ID',hidden:true},
                {field:'name',title:'电站名称',width:100},
                {field:'managerName',title:'代理商名称',width:100},
                {field:'partenerName',title:'合作伙伴名称',width:100},
                {field:'address',title:'电站地址',width:100},
                {field:'createTime',title:'创建时间',formatter: formatDateTime}
            ]],
            pagination: true,
            iconCls: 'icon-application_view_detail',
            singleSelect: false
        });
        $('#station').window('open');
    }

    //列出合作伙伴
    function listPartner(companyID){
    showPartnerWindow(companyID);
    }
    function showPartnerWindow(id) {
       var  queryParams = id;
       var dg = $('#partner_dl').datagrid();
       dg.datagrid({
            url:'/v1/api0/company_agent_Spy/list_partner',
            queryParams: {belongCompany:queryParams},
            columns:[[
                {field:'id',title:'公司ID',hidden:true},
                {field:'name',title:'公司名称',width:100},
                {field:'socialCode',title:'统一社会信用代码',width:100},
                {field:'leader',title:'负责人ID',hidden:true},
                {field:'leaderName',title:'负责人名称',width:100},
                {field:'mobile',title:'手机号',width:100},
                {field:'email',title:'邮箱',width:150},
                {field:'createTime',title:'创建时间',width:150,formatter: formatDateTime},
            ]],
            pagination: true,
            iconCls: 'icon-application_view_detail',
            singleSelect: false
        });
        $('#partner').window('open');
    }

    function closeWindow(){
        $('#station').window('close');
        $('#partner').window('close');
        $('#finance').window('close');
    }

    function showFinanceWindow(id) {
        var  queryParams = id;
        $.ajax({
        type: "post",
        url:'/v1/api0/account/detail',
        data:{companyID:queryParams},
        datatype: "json",
        success:function(data){
        var account = data.body;
        $('#balance').text(account.balance);
        $('#profit').text(account.profit);
        $('#recharge').text(account.recharge);
        $('#internet').text(account.internet);
        }
        });
        $('#finance').window('open');
    }
    function showRowImg(img){

  $('#dg').datagrid('selectRow', img);
  var row = $('#dg').datagrid('getSelected');
  var imgpath=row.licensePath;
  if(imgpath!=""&&imgpath!=null&&imgpath!=undefined){
  $("#showCompanyImageId").attr("src",serverPath+"/GetImage?bt=staticInfoImage&fn="+imgpath);
  $('#showImageId').window('open');
   }else{
   top.window.showMessage("该公司还未上传营业执照！");
   }
}
</script>
</body>
</html>
